package com.gexiaobao.pigeon.ui.pilot.activity

import android.content.res.ColorStateList
import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.gexiaobao.pigeon.app.base.BaseActivity
import com.gexiaobao.pigeon.app.ext.Constant
import com.gexiaobao.pigeon.app.ext.initClose
import com.gexiaobao.pigeon.databinding.ActivityMissionBinding
import com.gexiaobao.pigeon.ui.adapter.MyPagerAdapter
import com.gexiaobao.pigeon.ui.pilot.fragment.FragmentMissionCarVehicleRoute
import com.gexiaobao.pigeon.ui.pilot.fragment.FragmentMissionTrainingMap
import com.gexiaobao.pigeon.ui.pilot.fragment.FragmentSignPigeonDetail
import com.gexiaobao.pigeon.ui.pilot.fragment.FragmentTrainingMission
import com.gexiaobao.pigeon.viewmodel.ReleaseMissionViewModel
import me.hgj.jetpackmvvm.ext.util.setOnclickNoRepeat
import me.hgj.jetpackmvvm.util.startActivity

/**
 * @Author      : hxw
 * @Date        : 2023/6/1 11:31
 * @Describe    : 放飞任务信息
 */
class MissionInfoActivity : BaseActivity<ReleaseMissionViewModel, ActivityMissionBinding>() {

    private var mPassId = ""
    private var passType = 0
    private var passStatus = 0

    override fun initView(savedInstanceState: Bundle?) {
        /** tabLayout去除点击背景 */
        mDatabind.tabLayout.tabRippleColor = ColorStateList.valueOf(ContextCompat.getColor(this, android.R.color.transparent))
        passType = intent.getIntExtra("passType", 0)
        passStatus = intent.getIntExtra("passStatus", 0)
        mPassId = intent.getStringExtra("passId").toString()
        val title = intent.getStringExtra(Constant.TITLE)
        title?.let {
            mDatabind.toolbar.initClose(it) {
                finish()
            }
        }
        initViewPager()
    }

    override fun onBindViewClick() {
        super.onBindViewClick()
        setOnclickNoRepeat(mDatabind.tvDistanceMeasurement) {
            when (it) {
                mDatabind.tvDistanceMeasurement -> {
                    startActivity<MapDistanceActivity>("id" to mPassId)
                }
            }
        }
    }

    private fun initViewPager() {
        val tabTitles = if (passType == 2) {
            arrayListOf("放飞任务", "放飞明细", "放飞地图", "车辆路线")
        } else {
            arrayListOf("放飞任务", "集鸽明细", "放飞地图", "车辆路线")
        }
        val fragments = ArrayList<Fragment>()
        fragments.add(FragmentTrainingMission.newInstance(mPassId, passType, passStatus))
        fragments.add(FragmentSignPigeonDetail.newInstance(mPassId))
        fragments.add(FragmentMissionTrainingMap.newInstance(mPassId, passStatus))
        fragments.add(FragmentMissionCarVehicleRoute.newInstance(mPassId))
        mDatabind.viewPager.adapter = MyPagerAdapter(supportFragmentManager, this, fragments, tabTitles)
        mDatabind.viewPager.offscreenPageLimit = 4
        mDatabind.tabLayout.setupWithViewPager(mDatabind.viewPager)
    }
}